package com.czy.owner.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.InsuranceCompanyEntity;
import com.czy.owner.ui.store.NoBindStoreDetailActivity;
import com.czy.owner.utils.glide.GlideUtils;

import java.util.List;

/**
 * Created by King on 2017-05-17
 */

public class InsuranceCompanyAdapter extends BaseRecyclerAdapter<InsuranceCompanyEntity, InsuranceCompanyAdapter.InsuranceCompanyViewHolder> {
    public InsuranceCompanyAdapter(Context context, List<InsuranceCompanyEntity> data) {
        super(context, data);
    }

    @Override
    public void onBindViewHolder(InsuranceCompanyViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.bindData(data.get(position));
    }

    @Override
    public InsuranceCompanyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new InsuranceCompanyViewHolder(layoutInflater.inflate(R.layout.item_insurance_company, parent, false));
    }

    public class InsuranceCompanyViewHolder extends BaseRecyclerAdapter.ViewHolder {
        private TextView tvName;
        private ImageView ivLogo;

        public InsuranceCompanyViewHolder(View itemView) {
            super(itemView);
            tvName = (TextView) itemView.findViewById(R.id.tv_item_insurance_name);
            ivLogo = (ImageView) itemView.findViewById(R.id.iv_item_insurance_logo);
        }

        private void bindData(InsuranceCompanyEntity insuranceCompany) {
            tvName.setText(insuranceCompany.getInsuranceName());
            if (TextUtils.isEmpty(insuranceCompany.getInsuranceLogo())) {
                ivLogo.setImageResource(R.mipmap.default_icon);
            } else {
                GlideUtils.loadImage(mContext, insuranceCompany.getInsuranceLogo(), ivLogo, null, R.mipmap.default_icon, R.mipmap.default_icon);
            }
        }
    }
}
